<template>
  <div>
    <template v-if="dataType !== 'plan'">
      <el-table v-loading="loading" tooltip-effect="darkTable" :data="companyFinanceList" :height="!isCustom ? height - 55 : height" border @sort-change="dataSort">
        <el-table-column sortable="custom" :label="$t('融资轮次')" align="center" :prop="type === 'tyc' ? 'rounds' : 'financingRound'" min-width="100" show-overflow-tooltip />
        <el-table-column v-if="type !== 'tyc'" sortable="custom" :label="$t('融资方式')" align="center" prop="financingMode" :formatter="financingModeFormat" min-width="110" show-overflow-tooltip />
        <el-table-column sortable="custom" :label="$t('融资日期')" align="center" :prop="type === 'tyc' ? 'financingTime' : 'financingDate'" show-overflow-tooltip min-width="110">
          <template slot-scope="scope">
            <span v-if="type === 'tyc'">{{ parseTime(scope.row.financingTime) }}</span>
            <span v-else>{{ parseTime(scope.row.financingDate) }}</span>
          </template>
        </el-table-column>
        <el-table-column sortable="custom" :label="$t('融资总金额') + $t('金额单位')" align="center" :prop="type === 'tyc' ? 'transactionAmount' : 'financingTotalAmount'" show-overflow-tooltip min-width="150">
          <template slot-scope="scope">
            <span v-if="type === 'tyc'" class="money-text" :title="moneyFormat(isNaN(Number(scope.row.transactionAmount)) ? 0 : scope.row.transactionAmount || 0, 'w', 4, true)">{{ moneyFormat(isNaN(Number(scope.row.transactionAmount)) ? 0 : scope.row.transactionAmount || 0, 'w', 2, true) }}</span>
            <span v-else class="money-text" :title="moneyFormat(scope.row.financingTotalAmount || 0, 'w', 4, true)">{{ moneyFormat(scope.row.financingTotalAmount || 0, 'w', 2, true) }}</span>
          </template>
        </el-table-column>
        <el-table-column sortable="custom" :label="$t(type === 'tyc' ? '估值':'融资前估值') + $t('金额单位')" align="center" :prop="type === 'tyc' ? 'valuation' : 'financingBeforeValuation'" show-overflow-tooltip min-width="150">
          <template slot-scope="scope">
            <span v-if="type === 'tyc'" class="money-text" :title="moneyFormat(scope.row.valuation || 0, 'w', 4, true)">{{ moneyFormat(scope.row.valuation || 0, 'w', 2, true) }}</span>
            <span v-else class="money-text" :title="moneyFormat(scope.row.financingBeforeValuation || 0, 'w', 4, true)">{{ moneyFormat(scope.row.financingBeforeValuation || 0, 'w', 2, true) }}</span>
          </template>
        </el-table-column>
        <el-table-column v-if="type !== 'tyc'" sortable="custom" :label="$t('融资后估值') + $t('金额单位')" align="center" prop="financingAfterValuation" show-overflow-tooltip min-width="150">
          <template slot-scope="scope">
            <span :title="moneyFormat(scope.row.financingAfterValuation || 0, 'w', 4, true)" class="money-text">{{ moneyFormat(scope.row.financingAfterValuation || 0, 'w', 2, true) }}</span>
          </template>
        </el-table-column>
      </el-table>
    </template>
    <template v-else>
      <el-table v-loading="loading" tooltip-effect="darkTable" :data="companyFinanceList" :height="!isCustom ? height - 55 : height" border @sort-change="dataSort">
        <el-table-column sortable="custom" :label="$t('融资日期')" align="center" prop="financingTime" show-overflow-tooltip min-width="110">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.financingTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column sortable="custom" :label="$t('融资总金额') + $t('金额单位')" align="center" prop="financingAmount" show-overflow-tooltip min-width="150">
          <template slot-scope="scope">
            <span :title="moneyFormat(scope.row.financingAmount || 0, 'w', 4, true)" class="money-text">{{ moneyFormat(scope.row.financingAmount || 0, 'w', 2, true) }}</span>
          </template>
        </el-table-column>
        <el-table-column sortable="custom" :label="$t('预计估值') + $t('金额单位')" align="center" prop="estimatedValuation" show-overflow-tooltip min-width="150">
          <template slot-scope="scope">
            <span :title="moneyFormat(scope.row.estimatedValuation || 0, 'w', 4, true)" class="money-text">{{ moneyFormat(scope.row.estimatedValuation || 0, 'w', 2, true) }}</span>
          </template>
        </el-table-column>
        <el-table-column sortable="custom" :label="$t('融资计划')" align="center" prop="financingPlan" show-overflow-tooltip min-width="150" />
      </el-table>
    </template>
  </div>
</template>
<script>
import { listCompanyFinance } from '@/api/company/finance/companyFinance'
import { listCompanyFinanceTyc } from '@/api/company/finance/companyFinanceTyc'
import { listCompanyFollowFinance } from '@/api/company/followFinance/companyFollowFinance'
export default {
  name: 'CompanyFinanceInfo',
  props: {
    height: {
      type: Number,
      default: () => null
    },
    type: {
      type: String,
      default: undefined
    },
    isCustom: {
      type: Boolean,
      default: false
    },
    dataType: {
      type: String,
      default: undefined
    }
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 融资历史表格数据
      companyFinanceList: [],
      // 查询参数
      queryParams: {
        companyId: this.bussId,
        prop: undefined,
        order: undefined
      },
      // 表单参数
      form: {},
      financingModeOptions: []
    }
  },
  created() {
    this.getList()
    this.getDicts('financing_mode').then(response => {
      this.financingModeOptions = response.data
    })
  },
  methods: {
    /** 查询新闻信息列表 */
    getList() {
      this.loading = true
      this.queryParams.companyId = this.$route.query.companyId
      if (this.dataType !== 'plan') {
        if (this.type === 'tyc') {
          listCompanyFinanceTyc(this.queryParams).then(response => {
            this.companyFinanceList = response.rows
            this.total = response.total
            this.loading = false
          })
        } else {
          listCompanyFinance(this.queryParams).then(response => {
            this.companyFinanceList = response.rows
            this.total = response.total
            this.loading = false
          })
        }
      } else {
        listCompanyFollowFinance(this.queryParams).then(response => {
          this.companyFinanceList = response.rows
          this.loading = false
        })
      }
    },
    openNews(row) {
      if (row.newUrl.indexOf('http://') !== -1) {
        window.open(row.newUrl)
      } else if (row.newUrl.indexOf('https://') !== -1) {
        window.open(row.newUrl)
      } else {
        window.open('http://' + row.newUrl)
      }
    },
    // 融资方式字典翻译
    financingModeFormat(row) {
      return this.selectDictLabel(this.financingModeOptions, row.financingMode)
    },

    // 排序
    dataSort(column) {
      this.loading = true
      if (column.order !== null && column.order !== undefined && column.order !== '') {
        this.queryParams.prop = column.prop
        if (column.order === 'ascending') {
          this.queryParams.order = 'asc'
        } else if (column.order === 'descending') {
          this.queryParams.order = 'desc'
        }
      } else {
        this.queryParams.prop = undefined
        this.queryParams.order = undefined
      }
      this.getList()
    }
  }
}
</script>
